import api from '@/api';

export default {
  namespace: 'suggestion',

  state: {
    suggestions: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *query({ payload }, { call, put }) {
      const response = yield call(api.suggestion.query, payload);
      if (response.errorCode === 0) {
        yield put({
          type: 'saveSuggestions',
          payload: {
            list: response.data,
            pagination: response.pagination,
          },
        });
      }
      return response;
    },
    *detail({ payload }, { call, put }) {
      const response = yield call(api.suggestion.detail, payload);
      return response;
    },
  },

  reducers: {
    saveSuggestions(state, { payload }) {
      return {
        ...state,
        suggestions: payload,
      };
    },
  },
};
